/**
 * Copyright (c) 2023 myons Inc. All rights reserved.
 */
package cn.zmwh.common.core.utils;

import cn.hutool.json.JSONUtil;
import cn.zmwh.common.core.api.BaseErrorCode;
import cn.zmwh.common.core.api.Result;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @describe: token问题 、
 * @author: dmzmwh 、
 * @time: 2023-04-12 15:01 、
 */
public class AuthenticationUtil {

    public static void responseWriter(HttpServletResponse response) throws IOException {
        response.setStatus(BaseErrorCode.LOGIN_FAILURE);
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Cache-Control", "no-cache");
        response.setCharacterEncoding("UTF-8");
        response.setContentType("application/json;charset=UTF-8");
        response.getWriter().println(JSONUtil.parse(Result.failed(BaseErrorCode.LOGIN_FAILURE, "token失效")));
        response.getWriter().flush();
        return;
    }

    public static void responseWriter(HttpServletResponse response, Integer status, String msg) throws IOException {
        response.setStatus(200);
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Cache-Control", "no-cache");
        response.setCharacterEncoding("UTF-8");
        response.setContentType("application/json;charset=UTF-8");
        response.getWriter().println(JSONUtil.parse(Result.failed(status, msg)));
        response.getWriter().flush();
        return;
    }
}
